package com.lap.mybatis.starter.autoconfigure;

import com.lap.mybatis.starter.core.BatchExecutor;
import com.lap.mybatis.starter.core.BatchProcessor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;

@Slf4j
@AutoConfiguration
public class MybatisAutoConfiguration {

  @Bean
  @ConditionalOnBean(SqlSessionFactory.class)
  BatchExecutor batchExecutor(SqlSessionFactory sqlSessionFactory) {
    log.info("Initializer mybatis executor");
    return new BatchExecutor(sqlSessionFactory);
  }

  @Bean
  @ConditionalOnBean(BatchExecutor.class)
  BatchProcessor batchProcessor(BatchExecutor batchExecutor) {
    log.info("Initializer mybatis processor");
    return new BatchProcessor(batchExecutor);
  }
}
